if (!jsx3.lang.Class.forName("tibco.admin.enterpriseAssets.keyMgt.list.keystore")) {
    tibco.admin.Main.loadResource("tibco/admin/enterpriseAssets/keyMgt/list/jss/jss.xml", "tibco.admin", "jss29A", "ljss", false);
/**
**/
    jsx3.Class.defineClass(
            'tibco.admin.enterpriseAssets.keyMgt.list.keystore',
            jsx3.gui.LayoutGrid,
            null,
            function(keystore) {
                keystore.prototype.mtxList = null;
                keystore.prototype.multiselected = false;
                keystore.prototype.addMode = false;
                keystore.prototype.selection = new jsx3.util.List(0);

                keystore.prototype.subscribeAll = function() {
                    this.mtxList = this.getDescendantOfName('mtxKeystoresList29A');
                    this.deleteButton = this.getDescendantOfName("btnRemoveKeystore_29A");
                    var me = this;
                    tibco.admin.PubSub.subscribe(tibco.admin.enterpriseAssets.keystore.EventID.ADD_OVER, me, me.callgetKeystoresRegisteredWithEnterprise);
                    tibco.admin.PubSub.subscribe(tibco.admin.enterpriseAssets.keystore.EventID.DISABLED_REFRESH, me, me.setRefreshDisabled);
                    tibco.admin.PubSub.subscribe(tibco.admin.enterpriseAssets.keystore.EventID.ENABLED_REFRESH, me, me.setRefreshEnable);
                    this.callgetKeystoresRegisteredWithEnterprise();
                    this.loadPermissionButtons();
                }

                keystore.prototype.addInProgress = function(internal, menu) {
                    this.ignoreSelects = true;
                    var cachedTree = this.mtxList.getXML();
                    var objParent = cachedTree.getRootNode()
                    var record = objParent.createNode(jsx3.xml.Entity.TYPEELEMENT, "record");
                    var strID = jsx3.xml.CDF.getKey();
                    record.setAttribute("jsxid", strID)
                    record.setAttribute("name", tibco.admin.Main.getServer().getDynamicProperty("@@NewKeystore29A"));
                    if (!internal) record.setAttribute("URL", tibco.admin.Main.getServer().getDynamicProperty("@lblkeystoreExternal29A"));
                    record.setAttribute("modificationDate", Date());
                    objParent.appendChild(record);
                    menu.redrawRecord();
                    this.mtxList.repaintData();
                    this.mtxList.deselectAllRecords();
                    this.mtxList.selectRecord(strID);
                    this.addMode = true;
                    var msg = new Object();
                    msg.subject = tibco.admin.enterpriseAssets.keystore.EventID.KEYSTORE_ADD;
                    msg.keystoreType = (internal)?tibco.admin.Main.getServer().getDynamicProperty("@lblkeystoreInternal29A"):tibco.admin.Main.getServer().getDynamicProperty("@lblkeystoreExternal29A");
                    tibco.admin.PubSub.publish(msg);
                    msg = new Object();
                    msg.subject = tibco.admin.enterpriseAssets.keystore.EventID.DISABLED_REFRESH;
                    tibco.admin.PubSub.publish(msg);
                    this.updateButtons();
                }

                keystore.prototype.addOver = function() {
                    this.ignoreSelects = false;
                    this.addMode = false;
                    //this.callgetKeystoresRegisteredWithEnterprise();
                }

                keystore.prototype.tryToUnregisterKeystores = function() {
                    var cacheRecords = this.mtxList.getXML().selectNodes("//record[@jsxselected='1']");
                    tibco.admin.util.Log.SERVICE.trace("The number of selected records is [\n" + cacheRecords.getLength() + "]");
                    if (cacheRecords.getLength() == 0) {
                        tibco.admin.Main.alert(tibco.admin.Main.getServer().getDynamicProperty("@@NoSelected29A"), tibco.admin.Main.getServer().getDynamicProperty("@@PlzSelect29A"));
                        return;
                    }
                    var me = this;
                    tibco.admin.Main.confirm(
                            tibco.admin.Main.getServer().getDynamicProperty("@@deleteKeystores29A"),
                            tibco.admin.Main.getServer().getDynamicProperty("@@deleteKeystoresConfirm29A"),
                            function(dialog) {
                                dialog.doClose();
                                me.callunregisterKeystoresFromEnterprise();
                            }, null)
                }

                keystore.prototype.callgetKeystoresRegisteredWithEnterprise = function() {
                    var objService = tibco.admin.Main.loadService("tibco.admin",
                            "tibco/admin/enterpriseAssets/keyMgt/list/rules/getRegisteredKeystoreRules.xml",
                            "getKeystoresRegisteredWithEnterprise",
                            "Get Keystores Registered With Enterprise");
                    //subscribe and call
                    var me = this;
                    objService.subscribe(jsx3.net.Service.ON_SUCCESS, me, me.ongetKeystoresRegisteredWithEnterpriseSuccess);
                    objService.setEndpointURL(tibco.admin.util.ServiceHelper.getKeystoreEndpointURL());
                    objService.doCall();
                };

                keystore.prototype.ongetKeystoresRegisteredWithEnterpriseSuccess = function(objEvent) {
                    if (this.addMode || this.ignoreSelects) {
                        this.addOver();
                        var msg = new Object();
                        msg.subject = tibco.admin.enterpriseAssets.keystore.EventID.KEYSTORE_REFRESH;
                        tibco.admin.PubSub.publish(msg);
                    }
                    this.mtxList.repaint();
                    var cacheDoc = this.mtxList.getXML();
                    if (cacheDoc && cacheDoc.selectNodes("//record").getLength() > 0) {
                        var flag = false;
                        var iter = this.selection.iterator();
                        while (iter.hasNext()) {
                            var name = iter.next();
                            var record = this.mtxList.getXML().selectSingleNode("//record[@name='" + name + "']");
                            if (record) {
                                flag = true;
                                record.setAttribute("jsxselected", 1);
                            }
                            this.selection.clear();
                        }
                        this.publishSelect();
                    } else {
                        var msg = new Object();
                        msg.subject = tibco.admin.enterpriseAssets.keystore.EventID.KEYSTORE_SELECTED;
                        msg.entityID = null;
                        tibco.admin.PubSub.publish(msg);
                    }
                    this.updateButtons();
                };

                keystore.prototype.callunregisterKeystoresFromEnterprise = function() {
                    var objService = tibco.admin.Main.loadService("tibco.admin",
                            "tibco/admin/enterpriseAssets/keyMgt/list/rules/unregisterKeystoreRules.xml",
                            "unregisterKeystoresFromEnterprise",
                            tibco.admin.Main.getServer().getDynamicProperty("@contextUnregister29A"));
					
                    //subscribe and call
                    var me = this;
                    objService.subscribe(jsx3.net.Service.ON_SUCCESS, me, me.onunregisterKeystoresFromEnterpriseSuccess);
                    objService.setEndpointURL(tibco.admin.util.ServiceHelper.getKeystoreEndpointURL());
                    objService.doCall();
                };

                keystore.prototype.onunregisterKeystoresFromEnterpriseSuccess = function(objEvent) {
                    this.callgetKeystoresRegisteredWithEnterprise();
                };

                keystore.prototype.publishSelect = function() {
                    if (this.addMode) {
                        return;
                    }
                    if (this.ignoreSelects) {
                        var cacheDoc = this.mtxList.getXML();
                        if (cacheDoc) {
                            var recordIter = cacheDoc.getXML().selectNodes("//record[@jsxselected='1']").iterator();
                            while (recordIter.hasNext()) {
                                var record = recordIter.next();
                                record.setAttribute("jsxselected", 0);
                            }
                            var iter = this.selection.iterator();
                            while (iter.hasNext()) {
                                var name = iter.next();
                                var record = cacheDoc.getXML().selectSingleNode("//record[@name='" + name + "']");
                                if (record) {
                                    record.setAttribute("jsxselected", 1);
                                }
                            }
                        }
                        this.mtxList.repaint();
                        return;
                    }
                    else {
                        this.multiselected = false;
                        this.selection.clear();
                        var nodes = this.mtxList.getSelectedNodes();
                        var selectionSize = nodes.size();
                        for (var i = 0; i < selectionSize; i++) {
                            this.selection.add(nodes.getItem(i).getAttribute('name'));
                        }
                        if (selectionSize > 1) {
                            this.multiselected = true;
                        }
                    }
                    var sel = this.mtxList.getSelectedNodes();
                    if (sel && sel.size() == 1) {
                        var record = sel.getItem(0);
                        var msg = new Object();
                        msg.subject = tibco.admin.enterpriseAssets.keystore.EventID.KEYSTORE_SELECTED;
                        msg.keystoreName = record.getAttribute("name");
                        msg.entityID = record.getAttribute("entityId");
                        msg.keystoreDescription = record.getAttribute("description");
                        msg.keystoreLocation = record.getAttribute("fileLocation");
                        msg.keystoreURL = record.getAttribute("URL");
                        if (msg.keystoreURL)
                            msg.keystoreType = tibco.admin.Main.getServer().getDynamicProperty("@lblkeystoreExternal29A");
                        else
                            msg.keystoreType = tibco.admin.Main.getServer().getDynamicProperty("@lblkeystoreInternal29A");
                        msg.uploadedOn = record.getAttribute("modificationDate");
                        msg.hasEdit = record.getAttribute("hasEdit");
                        msg.hasOwner = record.getAttribute("hasOwner");
                        tibco.admin.PubSub.publish(msg);
                    }
                    else {
                        var msg = new Object();
                        msg.subject = tibco.admin.enterpriseAssets.keystore.EventID.KEYSTORE_SELECTED;
                        msg.entityID = null;
                        tibco.admin.PubSub.publish(msg);
                    }
                    this.updateButtons();
                };

                keystore.prototype.onRefresh = function() {
                    this.callgetKeystoresRegisteredWithEnterprise();
                };

                keystore.prototype.mtxKeystoresList29A_OnSelect = function(selectedIds) {
                    // publish the selected event.
                    this.publishSelect();
                }

                keystore.prototype.setRefreshDisabled = function(objEvent) {
                    this.getDescendantOfName("btnRefresh_29A").setEnabled(jsx3.gui.Form.STATEDISABLED, true);
                };

                keystore.prototype.setRefreshEnable = function(objEvent) {
                    this.getDescendantOfName("btnRefresh_29A").setEnabled(jsx3.gui.Form.STATEENABLED, true);
                }

                keystore.prototype.beginEditMode = function() {
                    this.ignoreSelects = true;
                    this.updateButtons();
                }

                keystore.prototype.endEditMode = function() {
                    this.ignoreSelects = false;
                    this.updateButtons();
                }

                keystore.prototype.updateButtons = function() {
                    var nodes = this.mtxList.getSelectedNodes();
                    var count = nodes.size();
                    var notOwner = 0;
                    var iter = nodes.iterator();
                    while (iter.hasNext()) {
                        var node = iter.next();
                        if (node.getAttribute("hasOwner") != "true") {
                            notOwner++;
                        }
                    }
                    this.getDescendantOfName("btnAddKeystore_29A").setEnabled((!this.ignoreSelects) ? jsx3.gui.Form.STATEENABLED : jsx3.gui.Form.STATEDISABLED, true);
                    this.deleteButton.setEnabled(((!this.ignoreSelects) && (count > 0) && (notOwner == 0)) ? jsx3.gui.Form.STATEENABLED : jsx3.gui.Form.STATEDISABLED, true);
                }

                /****************************************************************
                 *  Set permission and remove permission
                 *  Author: Alex Han
                 *  Date: 07-09-2007
                 ****************************************************************/

                keystore.prototype.loadPermissionButtons = function() {
                    var domNode = this.getDescendantOfName("panePermissionsButtons_29A");
                    this.permissions = tibco.admin.Main.loadUIResource(domNode, "tibco.admin", "tibco/admin/enterpriseAssets/userMgt/window/permissions/ui/setPermissions.xml", true);
                    this.permissions.initialize("Keystore", "entityId", "name", this.mtxList);
                    var me = this;
                    this.mtxList.switchPermissionBtn = function() {
                        me.permissions.switchPermissionBtn();
                    }
                }
                //=========== END OF SET PERMISSION ===============================================

            })
}